<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Gym Rat | Modify Program ${program.name }</title>
</head>
<body>
<jsp:include page="/includes/nav.jsp" />
<div class="result">${result }</div>
<h1>Modifying Program: ${program.name }</h1>
<h2>Entries in this Routine:</h2>
<form action="update" method="post">
<table width="100%">
	<tr class="tableHeader">
		<td>Routine</td>
		<td>Day</td>
		<td>Delete?</td>
	</tr>

	<c:if test="${program != null}">
		<c:forEach var="routine" items="${program.routines}"
			varStatus="status">
			<c:choose>
				<c:when test="${status.count % 2 == 1 }">
					<c:set var="rowClass" value="tableOddRow" />
				</c:when>
				<c:otherwise>
					<c:set var="rowClass" value="tableEvenRow" />
				</c:otherwise>
			</c:choose>
			<tr class="${rowClass}">
				<td>${routine.name } <input type="hidden" name="routineid"
					value="${routine.id }"></td>
				<td><input type="text" name="note"
					value="${routine.programNote}"></td>
				<td><input type="checkbox" name="deletebox"
					value="${routine.id }" /></td>
			</tr>
		</c:forEach>
	</c:if>
	<tr class="tableHeader">
		<td>Name</td>
		<td>Description</td>
		<td>Author</td>
	</tr>
	<tr class="tableHeader">
		<td><input type="text" name="name" value="${program.name }"></td>
		<td><textarea name="description">${program.description}</textarea></td>
		<td><input type="text" name="author" value="${program.author }"></td>
	</tr>
	<tr class="tableHeader">
		<td>Share? <input type="checkbox" name="share" 
		<c:if test='${program.shared == true}'>
		checked="checked"
		</c:if>></td>
		<td><input type="hidden" name="programid" value="${program.id}"></td>
		<td><input type="button" name="update" value="Update/Remove"
			onClick="submit()" /></td>
	</tr>
</table>
</form>
<hr />
<form action="${pageContext.request.contextPath}/program/addroutine"
	method="post">Add a Routine to this Program:<br>
Routine:<select name="add">
	<option value=0>---</option>
	<c:forEach var="routine" items="${routines }">
		<option value="${routine.id }">${routine.name }</option>
	</c:forEach>
</select><br>
<br>
Day/Frequency: ex: "Wednesday" or "A Day"<br>
<input type="text" name="note"><br>
<input type="submit" value="Add Routine"> <input type="hidden"
	name="id" value="${program.id }"></form>
<hr />
</body>
</html>